package work.shyk.msf.xml;

import org.nd4j.linalg.io.ClassPathResource;
import org.nd4j.linalg.io.Resource;
import work.shyk.msf.xml.model.Applications;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * description: <br>
 * createTime: 2019/9/1111:09 <br>
 *
 * @author zzh
 */
public class Main {

    public static Applications parse() throws Exception {
        // 读取XML文件
//        Resource resource = new ClassPathResource("eureka.xml");
        Resource resource = new ClassPathResource("eureka-Camden.xml");
        BufferedReader br = new BufferedReader(new InputStreamReader(resource.getInputStream(), "utf-8"));
        StringBuffer buffer = new StringBuffer();
        String line = "";

        while ((line = br.readLine()) !=null) {
            buffer.append(line);
        }

        br.close();

        // XML转为Java对象
        return XmlBuilder.xmlStrToOject(Applications.class, buffer.toString());
    }

    public static void main(String[] args) throws Exception {
        Applications applications = parse();
        System.out.println(applications.getApplications().size());
        System.out.println(XmlBuilder.objectToXml(applications));
    }
}
